<template>
	<view>
		<view class="formgroup_upImage  inputtext">
			<view style="padding-bottom: 20rpx;">
				<view class="labletitle" v-if="showLabel" style="margin-left: 40rpx;">
					<label>{{label}}</label>
					<text class="required" v-show="required">*</text>
				</view>
				<!-- <upload-annx :model="vModel" :upImgConfig="upImgBasic" @onUpImg="upBasicData"/> -->
				<u-upload :max-size="fileSize*1024*1024" :max-count="limit" :file-list="fileList" v-model="valueTitle"
					:size-type="['compressed']" :action="action" ref="uUpload" @on-remove="onRemove"
					:deletable='deletable' :show-progress='showProgress' :Status='Status' @on-uploaded='onUploaded'
					@on-choose-complete="onChoose" :limitType="['png', 'jpg', 'jpeg', 'webp', 'gif']"
					@click.stop="handleUpload"></u-upload>
			</view>
		</view>
	</view>
</template>

<script>
	import config from '@/common/js/config.js'
	let apiKey = uni.getStorageSync('apiKey') || 'api';
	let baseUrl = config.Global.baseUrl[apiKey].apiUrl;
	export default {
		props: {
			value: '',
			limit: {
				type: Number,
				default () {
					return 9
				}
			},
			fileSize: {
				type: Number,
				default () {
					return 2
				}
			},
			showLabel: {
				type: Boolean,
				default () {
					return true
				}
			},
			label: {
				type: String,
				default () {
					return '图片上传'
				}
			},
			vModel: {
				type: String,
				default () {
					return ''
				}
			},
			required: {
				type: Boolean,
				default () {
					return false
				}
			},
		},
		data() {
			return {
				valueTitle: '',
				fileList: [],
				action: baseUrl + "/api/Common/Uploader/annexpic",
				showUploadList: false,
				upLoadImgList: [],
				deletable: true,
				Status: 0,
				showProgress: true
			};
		},
		created() {
			//动态显示图片删除按钮
			let Status = uni.getStorageSync('F_Status');
			if (Status) {
				this.Status = Status
				if (this.Status == 1) {
					this.deletable = false
				}
			}
		},
		watch: {
			value(val) {
				console.log(val)
				this.fileList = val;
			}
		},

		methods: {
			handleUpload(event) {
				event.stopPropagation(); // 阻止事件冒泡 
			},
			onRemove(index, lists) {
				this.valueTitle = lists;
				this.handel(this.valueTitle)
			},

			onUploaded(lists, name) {
				this.valueTitle = lists
				this.handel(this.valueTitle)
			},
			onChoose() {
				this.$emit('uploading', true)
			},
			handel(lists) {
				let url;
				for (let i = 0; i < lists.length; i++) {
					if (lists[i].response) {
						lists[i].url = baseUrl + lists[i].response.data.url
					}
				}
				this.$emit('input', lists)
				this.$emit('uploading', false)
			}

		}
	}
</script>

<style>

</style>